<template>
	<view class="repayment-pop" v-if="show" @click="cancel">
		<view class="popup-main" @click.stop>
			<view class="list">
				<view class="item" v-for="(repayment, index) in repayments" :key="index" @click.stop="onselect(repayment)">
					<view class="name">{{repayment.name}}</view>
					<view class="desc">{{repayment.desc}}</view>
				</view>
				<view class="cancel" @click.stop="cancel">取 消</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			modelValue: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			modelValue: {
				handler (newVal) {
					this.show = newVal
				},
				immediate: true
			}
		},
		data () {
			return {
				show: false,
				repayments: [
					{name: '等额本息', desc: '月供每月相同、本金逐月递增、利息逐月递减', value: 'DEBX'},
					{name: '等额本金', desc: '月供每月递减、本金每月递减、利息每月递减', value: 'DEBJ'},
					{name: '先息后本', desc: '每月还固定利息，到期还全部本金', value: 'XXHB'},
					{name: '利随本清', desc: '到期日一次性还清借款本钱和利息', value: 'LSBQ'},
					{name: '等本等息', desc: '月供、本金、利息每月相同', value: 'DBDX'},
				]
			}
		},
		methods: {
			onselect (repayment) {
				this.$emit('select', repayment)
				this.cancel()
			},
			/** 取消 **/
			cancel () {
				this.$emit('update:modelValue', false)
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.repayment-pop {
		position: fixed;
		z-index: 2002;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0,0,0,.5);
		transition: all 0.5s;
		
		.popup-main {
			background-color: #fff;
			position: absolute;
			bottom: 0;
			left: 0;
			right: 0;
			max-height: 70vh;
			overflow: scroll;
			border-radius: 16rpx 16rpx 0 0;
			
			.list {
				.item {
					min-height: 100rpx;
					padding: 20rpx 0;
					border-bottom: 2rpx solid #f3f3f3;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.name {
						font-size: 30rpx;
						font-weight: 600;
						padding-bottom: 6rpx;
					}
					.desc {
						font-size: 24rpx;
						color: #666;
					}
				}
				.cancel {
					border-top: 20rpx solid #f3f3f3;
					height: 130rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32rpx;
					font-weight: 600;
					padding-bottom: env(safe-area-inset-bottom);
					
				}
			}
		}
	}
</style>